﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Lswweb.Model
{
    public class OrderInfo
    {
        #region Model
        private string _mobile;
        private string _address;
        private string _zip;
        private DateTime _datecreated;
        private OrderStatus _status= OrderStatus.WaitPayment;
        private string _remark;
        private decimal _logisticsprices;
        private decimal _productprices;
        private decimal _preferentialprices;
        private string _name;
        private string _phone;

        public OrderInfo()
        {
            this._datecreated = DateTime.Now;
        }

        public int Id { get; set; }

        public int UserId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Mobile
        {
            set { _mobile = value; }
            get { return _mobile; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Address
        {
            set { _address = value; }
            get { return _address; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Zip
        {
            set { _zip = value; }
            get { return _zip; }
        }
        /// <summary>
        /// 
        /// </summary>
        public DateTime DateCreated
        {
            set { _datecreated = value; }
            get { return _datecreated; }
        }
        /// <summary>
        /// 
        /// </summary>
        public OrderStatus Status
        {
            set { _status = value; }
            get { return _status; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Remark
        {
            set { _remark = value; }
            get { return _remark; }
        }
       
        /// <summary>
        /// 
        /// </summary>
        public decimal LogisticsPrices
        {
            set { _logisticsprices = value; }
            get { return _logisticsprices; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal ProductPrices
        {
            set { _productprices = value; }
            get { return _productprices; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal PreferentialPrices
        {
            set { _preferentialprices = value; }
            get { return _preferentialprices; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Phone
        {
            set { _phone = value; }
            get { return _phone; }
        }

        /// <summary>
        /// 物流类型
        /// </summary>
        public int LtsType
        {
            get 
            {
                if (this.Logistics == null)
                    return 0;

                return this.Logistics.LtsType; 
            }
            set
            {
                if (this.Logistics == null)
                    this.Logistics = new LogisticsInfo() { LtsType = value };
                else
                    this.Logistics.LtsType = value;
            }
        }

        #endregion Model

        public decimal TotalPrices
        {
            get { return ProductPrices + LogisticsPrices + PreferentialPrices + Insurance; }
        }

        public IList<OrderItemInfo> OrderItems { get; set; }

        public PaymentInfo Payment { get; set; }

        public LogisticsInfo Logistics { get; set; }

        public int CityId { get; set; }

        public string CompanyName { get; set; }

        public decimal Insurance { get; set; }
    }

    /// <summary>
    /// 订单物品信息
    /// </summary>
    public class OrderItemInfo
    {
        private IDictionary<string, Object> other;

        public OrderItemInfo(int productId, int qty, decimal price)
        {
            this.Quantity = qty;
            this.Price = price;
            this.ProductId = productId;
            this.other = new Dictionary<string, Object>();
        }

        /// <summary>
        /// 
        /// </summary>
        public int OrderId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int ProductId { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public int Quantity { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public Decimal Price { get; private set; }

        public IDictionary<string, Object> Others
        {
            get { return this.other; }
        }

        public Decimal Subtotal
        {
            get { return (decimal)(this.Quantity * this.Price); }
        }
    }

    /// <summary>
    /// 付款信息
    /// </summary>
    public class PaymentInfo
    {
        public PaymentInfo()
        {
            this.DateCreated = DateTime.Now;
        }

        public int OrderId { get; set; }

        public string BankName { get; set; }

        public string BankAccounts { get; set; }

        public decimal Amount { get; set; }

        public DateTime Dates { get; set; }

        public string Remark { get; set; }

        public DateTime DateCreated { get; set; }

        public string CurrencyType { get; set; }
    }

    /// <summary>
    /// 物流信息
    /// </summary>
    public class LogisticsInfo
    {
        #region Model
        private int _orderid;
        private string _name;
        private string _trackingnumber;
        private DateTime _datecreated;

        public LogisticsInfo()
        {
            this._datecreated = DateTime.Now;
        }

        /// <summary>
        /// 
        /// </summary>
        public int OrderId
        {
            set { _orderid = value; }
            get { return _orderid; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string TrackingNumber
        {
            set { _trackingnumber = value; }
            get { return _trackingnumber; }
        }
        /// <summary>
        /// 
        /// </summary>
        public DateTime DateCreated
        {
            set { _datecreated = value; }
            get { return _datecreated; }
        }

        public DateTime? SendDates { get; set; }

        public string Remark { get; set; }

        public int LtsType { get; set; }

        #endregion Model
    }

    public enum OrderStatus
    {
        /// <summary>
        /// 新定单等待付款
        /// </summary>
        WaitPayment=1,
        /// <summary>
        /// 已付款等待确认
        /// </summary>
        WaitConfirmation = 2,
        /// <summary>
        /// 已付款，备货中
        /// </summary>
        InStock=3,
        /// <summary>
        /// 已发货，等待接收
        /// </summary>
        WaitReceive=4,
        /// <summary>
        /// 确认收货，定单完成
        /// </summary>
        ConfirmationReceipt = 5,
        /// <summary>
        /// 其它异常原因，订单结束
        /// </summary>
        AbnormityEnd=6
    }
}
